home *** CD-ROM | disk | FTP | other *** search
- PROGRAM TESTOPT_;
- {Test GETOPT_.PAS and GETOTP2_.PAS}
- {$DEFINE OPT2}
- {$IFNDEF OPT2}
- USES GETOPT_;
- const
- optionS : pChar = 'A:F:PuU:wXZ:';
- {$ELSE}
- USES GETOPT2_;
- const
- optionS : pChar = 'AFUZ';
- {$ENDIF}
- var
- ch :Char;
- i :Integer;
- begin
- i := 0;
- writeln;
- writeln('----');
- repeat
- ch := getOpt(optionS);
- if ch <> EOFch
- then begin
- inc(i);
- write('***** Item ',i:2, ' is ');
- if ch = NONOPTch
- then
- write('NON SWITCH')
- else if ch = ERRORch
- then
- write('ERROR ')
- else
- write('SWITCH ',ch);
- if optArg <> nil
- then
- write(': ',optarg);
- writeln
- end;
- { the following CASE statement is what you would do in your
- program}
- case ch of
- 'A', 'F', 'U', 'Z':
- writeln(optArg, ' is a nice argument for switch ',ch);
- 'P','w','X':
- writeln(ch, ' is a lonesome switch');
- 'u','U':
- writeln('U and u are the same to me');
- NONOPTch:
- writeln('I''m ignoring non-switches like ', optarg);
- ERRORch:
- writeln('That''s a buggy command-line');
- else
- writeln('no comments about switches I don''t know');
- end;
- until (ch = EOFch);
- writeln;
- for i := 1 to argc
- do
- writeln('argv[', i,'] is ',argv[i])
- end.